package com.example.utils;

import org.apache.tomcat.util.http.fileupload.FileUtils;
import java.io.File;
import java.io.IOException;

/*
@description:
@ClassName ShardUploadUtils
@author chen
@create 2025-05-13 22:32
@Version 1.0
*/
public class ShardUploadUtils
{

    /*
     * @param file
     * @==============History===============<br/>
     * @Description //   当文件不存在的时候创建文件
     * @Date 2025-5-13 23:11
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return java.io.File
     */
    public static File createFileNotExists(File file) throws IOException
    {
        if (!file.exists())
        {
            FileUtils.forceMkdirParent(file);
            file.createNewFile();
        }
        return file;
    }



    /*
     * @param fileSize 文件大小(byte)
     * @param partSize 分片大小(byte)
     * @==============History===============<br/>
     * @Description //   获取分片数量
     * @Date 2025-5-13 22:33
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return int
     */
    public static int shardNum(long fileSize, long partSize)
    {
        if (fileSize % partSize == 0)
        {
            return (int) (fileSize / partSize);
        }
        else
        {
            return (int) (fileSize / partSize) + 1;
        }
    }
}
